package com.tedu.movie.controller;

import com.tedu.movie.pojo.Item;
import com.tedu.movie.pojo.ServerResult;
import com.tedu.movie.pojo.Ticket;
import com.tedu.movie.pojo.TicketItemVO;
import com.tedu.movie.service.TicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
public class TicketController {

    @Autowired
    TicketService ticketService;
    @RequestMapping("/ticket/selectAll")
    public ServerResult selectAll(){
        List<TicketItemVO> list = ticketService.selectAll();
        return new ServerResult(0,"查询成功",list);
    }

    @RequestMapping("/ticket/selectByCinemaId")
    public ServerResult selectByCinemaId(String id){
        List<Ticket> list=ticketService.selectByCinemaId(id);
        return new ServerResult(0,"查询成功",list);
    }

    @RequestMapping("/ticket/selectById")
    public ServerResult selectById(String id){
        Ticket ticket =ticketService.selectById(id);
        return new ServerResult(0,"查询成功",ticket);
    }

    @RequestMapping("/ticket/insertTicket")
    public ServerResult insertTicket(Ticket ticket){
        boolean isSuccess=ticketService.insertTicket(ticket);
        if(isSuccess){
            return new ServerResult(0,"添加成功",ticket);
        }else {
            return new ServerResult(1,"添加失败",ticket);
        }
    }

    @RequestMapping("/ticket/deleteTicket")
    public ServerResult deleteTicket(String id){
        boolean isSuccess=ticketService.deleteTicket(id);
        if(isSuccess){
            return new ServerResult(0,"删除成功",null);
        }else{
            return new ServerResult(1,"删除失败",null);
        }
    }

    @RequestMapping("/ticket/updateTicket")
    public ServerResult updateTicket(Ticket ticket){
        boolean isSuccess=ticketService.updateTicket(ticket);
        if (isSuccess){
            return new ServerResult(0,"更新成功",null);
        }else {
            return new ServerResult(1,"更新失败",null);
        }
    }

    @RequestMapping("/ticket/selectByStatus")
    public ServerResult selectByStatus(boolean status){
        List<Ticket> list=ticketService.selectByStatus(status);
        return new ServerResult(0,"查询成功",list);
    }

}
